package com.bsj.travel.device.factory;

import com.bsj.travel.def.common.DO.ProductDO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.def.global.JsonResultEnum;
import com.bsj.travel.device.RemoteProductService;
import com.bsj.travel.util.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 产品-设备服务降级处理
 * @date 2023/11/23
 */
@Component
@Slf4j
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {

    @Override
    public RemoteProductService create(Throwable cause) {
        log.error("[产品-设备]获取节点服务调用失败: {}", ExceptionUtil.getStackStr(cause));
        return new RemoteProductService() {
            @Override
            public JsonResult add(ProductDO productDO) {
                return JsonResult.fail(JsonResultEnum.PRODUCT_IS_ADD_FAIL);
            }

            @Override
            public JsonResult<List<ProductDO>> list(Integer type, String source) {
                return JsonResult.fail(JsonResultEnum.PRODUCT_LIST_IS_QUERY_FAIL);
            }

            @Override
            public JsonResult delete(Long productId) {
                return JsonResult.fail(JsonResultEnum.PRODUCT_IS_DELETE_FAIL);
            }

            @Override
            public JsonResult getAllList(String productKey, String source) {
                return JsonResult.fail(JsonResultEnum.PRODUCT_TOPIC_QUERY_ALL_FAIL);
            }
        };
    }
}
